﻿
@{
    ViewBag.Title = "LoadForm";
}

<h2>Pagination</h2>
<div class="pager">
    <button>First</button>
    <button>Prev</button>
    <button>Next</button>
    <button>Last</button>
</div>

<div id="results"></div>

@section scripts{
    <script>
        $(function () {
            fnLoadPage();

            $(".pager button").click(function () {
                label = $(this).text().toLowerCase();
                switch (label) {
                    case "first":
                        pageNo = 0;
                        break;
                    case "prev":
                        if (pageNo > 0) {
                            pageNo--;
                        }
                        break;
                    case "next":
                        if (pageNo < pageCount - 1) {
                            pageNo++;
                        }
                        break;
                    case "last":
                        pageNo = pageCount - 1;
                        break;
                }
                fnLoadPage();
            });
        });

        var pageNo = 0;
        var pageCount = @ViewBag.PageCount
        function fnLoadPage() {
            $.ajax({
                url: "/Product/LoadPage",
                data: { pageNo: pageNo },
                success: function (response) {
                    $("#results").html(response);
                }
            });
        }
    </script>
}

